﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using log4net;
using System.Reflection;
using QualityRpt.Dao;
using QualityRpt.Utils;

namespace QualityRpt.Service
{
    /// <summary>
    /// BaseService 的摘要说明
    /// 服务类的基类
    /// </summary>
    public class BaseService
    {
        /// <summary>
        /// 获得数据库持久化实现类的实例
        /// </summary>
        /// <param name="imp_name">接口名称</param>
        /// <returns></returns>
        protected static object CreateDaoInstance(string if_name)
        {
            string dao_imp = ConfigurationManager.AppSettings["DaoImp"];
            if (!dao_hash.ContainsKey(if_name))
            {
                string name = if_name.Substring(1, if_name.Length - 1);
                string dao_full_name = "QualityRpt.Dao." + dao_imp + "." + name;
                Type impdao_type = Type.GetType(dao_full_name);
                if (null == impdao_type)
                {
                    throw new Exception("not found class " + dao_full_name);
                }
                object impdaoInstance = Activator.CreateInstance(impdao_type);
                dao_hash.Add(if_name, impdaoInstance);
            }
            return dao_hash[if_name];
        }
        /// <summary>
        /// dao 哈希
        /// </summary>
        private static Hashtable dao_hash = new Hashtable();
    }
}
